#pragma once
#include <AVUIFrameworkElement.h>
#include <AVUIIAddChild.h>
#include <AVUIControl.h>

namespace AVUI {

class FormattedText;

class TextBlock : public FrameworkElement, public IAddChild
{
public:

    DECLARE_ELEMENT(TextBlock, FrameworkElement);

    DECLARE_DEPENDENCY_PROPERTY_BEGIN(Text);
        DECLARE_ATTRIBUTE_CONTENTPROPERTY();
    DECLARE_DEPENDENCY_PROPERTY_END();
    TRefCountedPtr<String> get_Text() { return (String*)(Object*)GetValue(get_TextProperty()); }
    void set_Text(String* pValue) { SetValue(get_TextProperty(), (Object*)pValue); } 

    DECLARE_DEPENDENCY_PROPERTY(FontSize);
    float get_FontSize() { return AVUI::UnboxValue<float>(GetValue(get_FontSizeProperty())); }
    void set_FontSize(float value) { SetValue(get_FontSizeProperty(), AVUI::BoxValue(value)); } 

    DECLARE_DEPENDENCY_PROPERTY(Foreground);
    TRefCountedPtr<Brush> get_Foreground() { return (Brush*)(Object*)GetValue(get_ForegroundProperty()); }
    void set_Foreground(Brush* pValue) { SetValue(get_ForegroundProperty(), (Object*)pValue); } 

    DECLARE_DEPENDENCY_PROPERTY(FontFamily);
    String* get_FontFamily() { return object_cast<String>(GetValue(get_FontFamilyProperty())); }
    void set_FontFamily(String* pFontFamily) { SetValue(get_FontFamilyProperty(), pFontFamily); }

    DECLARE_DEPENDENCY_PROPERTY(TextWrapping);
    TextWrapping::Enum get_TextWrapping() { return (TextWrapping::Enum)(AVUI::UnboxValue<int>(GetValue(get_TextWrappingProperty()))); }
    void set_TextWrapping(TextWrapping::Enum value) { SetValue(get_TextWrappingProperty(), AVUI::BoxValue<int>(value)); } 

    DECLARE_DEPENDENCY_PROPERTY(TextTrimming);
    TextTrimming::Enum get_TextTrimming() { return (TextTrimming::Enum)(AVUI::UnboxValue<int>(GetValue(get_TextTrimmingProperty()))); }
    void set_TextTrimming(TextTrimming::Enum value) { SetValue(get_TextTrimmingProperty(), AVUI::BoxValue<int>(value)); } 

    DECLARE_DEPENDENCY_PROPERTY(TextAlignment);
    TextAlignment::Enum get_TextAlignment() { return (TextAlignment::Enum)(AVUI::UnboxValue<int>(GetValue(get_TextAlignmentProperty()))); }
    void set_TextAlignment(TextAlignment::Enum value) { SetValue(get_TextAlignmentProperty(), AVUI::BoxValue<int>(value)); } 

    TextBlock() { }
    virtual ~TextBlock();

private:
    static void StaticConstructor();
    virtual void AddChild(Object* pValue);
    virtual void AddText(String* pText);


    Size MeasureOverride(const Size& constraintSize);
    Size ArrangeOverride(const Size& constraintSize);
    void OnRender(DrawingContext& drawingContext);
    void ClearFormattedText();

    ItemStructList<TRefCountedPtr<FormattedText> > m_formattedText;
};


}; // namespace AVUI
